package logic

import (
	"context"
	"go.uber.org/zap"
	"smart-health-platforms/pkg"
	"user_srv/internal/dao"
	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type SignInLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSignInLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SignInLogic {
	return &SignInLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SignInLogic) SignIn(in *user.SignInRequest) (*user.SignInResponse, error) {
	record, err := dao.CreateSignRecord(in) //创建签到记录
	if err != nil {
		pkg.Error("创建签到记录失败", zap.Error(err))
		return nil, err
	}
	return &user.SignInResponse{
		Success: true,                 //签到是否成功，true表示成功，false表示失败
		Points:  int32(record.Points), //签到获得的积分
		Message: "签到成功",
	}, nil
}
